package com.qing.controller;

import com.qing.pojo.vo.EmployeeInfVo;
import com.qing.pojo.vo.EmployeeSalaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import com.qing.service.EmployeeService;
import com.qing.pojo.Employee;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qinghua
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @PostMapping("/insert")
    public Employee save(@RequestBody Employee employee) {
        employeeService.saveOrUpdate(employee);
        return employee;
    }

    @PostMapping("/insertByExcel")
    public Boolean insertByExcel(@RequestParam MultipartFile file) {
        return employeeService.insertByExcel(file);
    }

    @GetMapping("/deleteById/{employeeId}/{userId}")
    public Boolean delete(@PathVariable Integer employeeId, @PathVariable Integer userId) {
        return employeeService.deleteEmployee(employeeId, userId);
    }

    @PostMapping("/updateInf")
    public Boolean updateInf(@RequestBody EmployeeInfVo employeeInfVo) {
        return employeeService.updateInf(employeeInfVo);
    }

    @GetMapping("/queryAll")
    public List<Employee> queryAll() {
        return employeeService.list();
    }

    @GetMapping("/queryById/{id}")
    public Employee findOne(@PathVariable Integer id) {
        return employeeService.getById(id);
    }

    /**
     * 查询员工所有信息（并添加表中外键id对应的name）
     *
     * @return {@link List< EmployeeSalaryVo> }
     */
    @GetMapping("/queryAllEmployeeInf")
    public List<EmployeeSalaryVo> queryAllEmployeeInf() {
        return employeeService.queryAllEmployeeInf();
    }

    @GetMapping("/queryAllEmployeeSalary")
    public List<EmployeeSalaryVo> queryAllEmployeeSalary() {
        return employeeService.queryAllEmployeeSalary();
    }

}

